{extend name="public/container"}
{block name="content"}
<style>
    .dropdown-menu li a i{
        width: 10px;
    }
</style>
<div class="row">
    <div class="col-sm-12">
        <div class="ibox">
            <div class="ibox-title">
                <button type="button" class="btn btn-w-m btn-primary" onclick="$eb.createModalFrame(this.innerText,'{:Url('create')}')">添加设备</button>
                <div class="ibox-tools">

                </div>
            </div>
            <div class="ibox-content">
                <div class="row">
                    <div class="m-b m-l">
                        <form action="" class="form-inline">

                            <select name="status" aria-controls="editable" class="form-control input-sm">
                                <option value="">工作状态</option>
                                <option value="10" {eq name="where.status" value="10"}selected="selected"{/eq}>正常</option>
                                <option value="20" {eq name="where.status" value="20"}selected="selected"{/eq}>失联</option>
                                <option value="30" {eq name="where.status" value="30"}selected="selected"{/eq}>其他(故障)</option>
                            </select>
                            <select name="store_id" aria-controls="editable" class="form-control input-sm">
                                <option value="">选择门店</option>
                                {volist; name="store_list" id="vo"}
                                <option value="{$vo.id}">{$vo.name}</option>
                                {/volist}
                            </select>
                            <div class="input-group">
                                <input type="text" name="device_name" value="{$where.device_name}" placeholder="请输入设备名称" class="input-sm form-control"> <span class="input-group-btn">
                                    <button type="submit" class="btn btn-sm btn-primary"> <i class="fa fa-search" ></i>搜索</button> </span>
                            </div>
                        </form>
                    </div>

                </div>
                <div class="table-responsive" style="overflow:visible">
                    <table class="table table-striped  table-bordered">
                        <thead>
                        <tr>

                            <th class="text-center">编号</th>
                            <th class="text-center">设备名称</th>
                            <th class="text-center">设备编号</th>
                            <th class="text-center">设备地址</th>
                            <th class="text-center">设备工作时长</th>
                            <th class="text-center">设备二维码</th>
                            <th class="text-center">设备状态</th>
                            <th class="text-center">最新上电时间</th>
                            <th class="text-center">添加时间</th>
                            <th class="text-center" width="10%">操作</th>
                        </tr>
                        </thead>
                        <tbody class="">
                        {volist; name="list" id="vo"}
                        <tr>
                            <td class="text-center">
                                {$vo.id}
                            </td>
                            <td class="text-center">
                                {$vo.device_name}
                            </td>
                            <td class="text-center">
                                {$vo.device_no}
                            </td>
                            <td class="text-center">
                                {$vo.address}
                            </td>
                            <td class="text-center">
                                {$vo.work_time|Sec2Time}
                            </td>
                            <td class="text-center">
                                {if $vo.url_code }
                                <img src="{$vo.url_code}" alt="" width="50">
                                {/if}
                                {if !$vo.url_code}
                                设备二维码未生成不存在
                                {/if}
                            </td>
                            <td class="text-center">
                                {if $vo.status == 10}
                                    正常
                                {/if}
                                {if $vo.status == 20}
                                    失联
                                {/if}
                                {if $vo.status == 30}
                                    维护
                                {/if}
                            </td>
                            <td class="text-center">
                                {$vo.power_time == 0?"暂未获取":$vo.power_time|date='Y-m-d H:i:s'}
                            </td>
                            <td class="text-center">
                                {$vo.add_time|date='Y-m-d H:i:s'}
                            </td>
                            <td class="text-center">
                                <div class="input-group-btn js-group-btn">
                                    <div class="btn-group">
                                        <button data-toggle="dropdown" class="btn btn-warning btn-xs dropdown-toggle"
                                                aria-expanded="false">操作
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu">
                                            {if condition="$vo['status']"}
                                            <li>
                                                <a href="javascript:void(0);" onclick="$eb.createModalFrame(this.innerText+' [{$vo.title}] 设备','{:Url('edit',['id'=>$vo['id']])}')">
                                                    <i class="fa  fa-male"></i> 编辑
                                                </a>
                                            </li>
                                            <li>
                                                <a href="javascript:void(0);" class="del" data-url="{:Url('repair',array('id'=>$vo['id']))}">
                                                    <i class="fa  fa-yelp"></i> 维护
                                                </a>
                                            </li>
                                            <li>
                                                <a href="javascript:void(0);" class="del" data-url="{:Url('restart',array('id'=>$vo['id']))}">
                                                    <i class="fa  fa-yelp"></i> 生成二维码
                                                </a>
                                            </li>
                                            {/if}
                                            <li>
                                                <a href="javascript:void(0);" class="delstor" data-url="{:Url('delete',array('id'=>$vo['id']))}">
                                                    <i class="fa fa-warning"></i> 删除
                                                </a>
                                            </li>
                                            <li>
                                                <a href="{:Url('debug',['id'=>$vo['id']])}" >
                                                    <i class="fa fa-calendar"></i> 设备调试
                                                </a>
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        {/volist}
                        </tbody>
                    </table>
                </div>
                {include file="public/inner_page"}
            </div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script>
    $('.js-group-btn').on('click',function(){
        $('.js-group-btn').css({zIndex:1});
        $(this).css({zIndex:100});
    });
    $('.del').on('click',function(){
        window.t = $(this);
        var _this = $(this),url =_this.data('url');
        $eb.$swal('delete',function(){
            $eb.axios.get(url).then(function(res){
                console.log(res);
                if(res.status == 200 && res.data.code == 200) {
                    $eb.$swal('success',res.data.msg);
//                        _this.parents('tr').remove();
                }else
                    return Promise.reject(res.data.msg || '修改失败')
            }).catch(function(err){
                $eb.$swal('error',err);
            });
        },{'title':'您确定要修改设备的状态吗？','text':'修改后将无法恢复并且已发出的优惠券将失效,请谨慎操作！','confirm':'是的，我要修改'})
    });
    $('.delstor').on('click',function(){
        window.t = $(this);
        var _this = $(this),url =_this.data('url');
        $eb.$swal('delete',function(){
            $eb.axios.get(url).then(function(res){
                console.log(res);
                if(res.status == 200 && res.data.code == 200) {
                    $eb.$swal('success',res.data.msg);
                    _this.parents('tr').remove();
                }else
                    return Promise.reject(res.data.msg || '删除失败')
            }).catch(function(err){
                $eb.$swal('error',err);
            });
        },{'title':'您确定要删除设备吗？','text':'删除后将无法恢复,请谨慎操作！','confirm':'是的，我要删除'})
    });
    $(".open_image").on('click',function (e) {
        var image = $(this).data('image');
        $eb.openImage(image);
    })
</script>
{/block}